package model;

import interfaces.IPlateformePlugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class PluginStorage {

	private Map<String, IPlateformePlugin> loadedPlugins;
	private Map<String,IPlateformePlugin> availablePlugins;
	private PluginPath pluginPath;
	
	public PluginStorage(){
		this.loadedPlugins = new HashMap<String,IPlateformePlugin>();
		this.availablePlugins = new HashMap<String,IPlateformePlugin>();
	}
	
	public ArrayList<Object> getListOfLoadedPlugins() {
		// TODO Auto-generated method stub
		ArrayList<Object> ar = new ArrayList<Object>();
		for(IPlateformePlugin p : this.loadedPlugins.values()){
			ar.add(((LazyPlugin)p).getRealPlugin());
		}
		return ar;
	}

	public ArrayList<Object> getListOfAvailablePlugins() {
		// TODO Auto-generated method stub
		ArrayList<Object> ar = new ArrayList<Object>();
		for(IPlateformePlugin p : this.availablePlugins.values()){
			ar.add(((LazyPlugin)p).getRealPlugin());
		}
		return ar;
	}
	
	public boolean isThePluginLoaded(String myPluginClass){
		return this.loadedPlugins.containsKey(myPluginClass);
	}
	
	public boolean isThePluginAlreadyAvailable(String myPluginClass){
		return this.availablePlugins.containsKey(myPluginClass);
	}
	
	public void addLoadedPlugin(String s, IPlateformePlugin p){
		this.loadedPlugins.put(s, p);
	}
	
	public void addAvailablePlugin(String name, IPlateformePlugin p){
		this.availablePlugins.put(name,p);
	}
	
	public void unloadPlugin(String myPluginClass){
		this.loadedPlugins.remove(myPluginClass);
	}
	
	public ArrayList<String> getNameOfAvailablePlugins(){
		return new ArrayList<String>(this.availablePlugins.keySet());
	}

	public IPlateformePlugin getPluginByName(String namePlugin) {
		// TODO Auto-generated method stub
		return this.availablePlugins.get(namePlugin);
	}

	public ArrayList<String> getNameOfLoadedPlugins() {
		// TODO Auto-generated method stub
		return new ArrayList<String>(this.loadedPlugins.keySet());
	}

	public void cleanListOfAvailablePlugins() {
		// TODO Auto-generated method stub
		this.availablePlugins.clear();
	}

	public PluginPath getPluginPath() {
		return this.pluginPath;
	}

	public void setPluginPath(PluginPath pluginPath) {
		this.pluginPath = pluginPath;
	}
}
